package ClassParserTest;


import java.io.File;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import devaluator.functionality.Classparser;

public class ClassParserTests {
	List<String> temp;
	File tempFile=null;
	Classparser c = null;
	Integer act,exp;
	@Before
	public void setUp() throws Exception {
		//TestedFile.javaa is for testing purpose only
		tempFile = new File("unittests/DummyFilesForTesting");
		if (tempFile.exists())
		c = new Classparser(tempFile);
	}
	
	
	@Test
	//check if the classparser constructor works with a real file
	public void testConstructor (){
		assertNotNull("It should not be Null",c);
	}
	
	@Test
	//check the match() method in the Classparser
	//The match() method should catch the class name in "TestedFile.java"
	public void testMatchMethodForClasses() {
		act = 0;
		exp = 1;
		temp = c.match();
		for (String aString: temp)
			if (aString.equals("public class TestedFile "))
				act = act +1;
		assertEquals("match method fails in finding classes",exp,act);
	}
	
	@Test
	//check the match() method in the Classparser
	//The match() method should catch interface name in "TestedInterface.java"
	public void testMatchMethodForInterfaces() {
		act = 0;
		exp = 1;
		temp = c.match();
		for (String aString: temp)
			if (aString.equals("public interface TestedInterface "))
				act = act +1;
		assertEquals("match method fails in finding interfaces",exp,act);
	}
	
	@Test
	//check the match() method in the Classparser
	//The match() method should catch user defined package name in "TestedPackage.java"
	public void testMatchMethodForUserPackages() {
		act = 0;
		exp = 1;
		temp = c.match();
		for (String aString: temp){
			if (aString.equals("package DummyFilesForTesting;")){
				act = act +1;
				break;
			}  
		};
		assertEquals("match method fails in finding packages",exp,act);
	}
	
	@Test
	//check the match() method in the Classparser
	//The match() method should catch Java package name in "TestedPackage.java"
	public void testMatchMethodForJavaPackages() {
		act = 0;
		exp = 1;
		temp = c.match();
		for (String aString: temp){
			if (aString.equals("import java.util.Random;")){
				act = act +1;
				break;
			}  
		};
		assertEquals("match method fails in finding packages",exp,act);
		//Parser is not working well for packages...need to fix 
	}
	
	
	@After
	public void tearDown() {
        c = null;
        
    }


}
